<template>
	<view>
		<view class="cu-bar bg-white search">
			<view class="search-form">
				<text class="cuIcon-search"></text>
				<input type="text" v-model="filter" placeholder="输入订单编号搜索" confirm-type="search" @confirm="search"></input>
			</view>
			<view class="action">
				<button class="cu-btn bg-gradual-green shadow-blur" @tap="search">搜索</button>
			</view>
		</view>
		<scroll-view @scrolltolower="scrolltolower" scroll-y="true" style="height:calc(100vh - 100rpx)">
			<!-- <Order v-for="(item,index) in list" :key="index" :item="item"></Order> -->
			<view v-if="list.length===0" class="flex flex-direction align-center">
				<view style="font-size:200rpx;margin-top:200rpx;" class="cuIcon-search text-orange"></view>
				<view class="text-orange text-xl margin-xl">暂时没有结果。。。</view>
			</view>
			<view class="margin-xs radius bg-gray solids" v-for="(item,index) in list" :key="index">
				<view class="padding-sm flex">
					<view class="basis-xl" @tap="clickOrderId(item._id)">订单编号:{{item._id}}<text class="margin-left-xs text-purple">复制</text></view>
					<view class="basis-xs text-right">{{$u.timeFrom(item.addTime)}}</view>
				</view>
				<view v-for="(goods,gIndex) in item.goodsArr" :key="gIndex" class="padding-sm flex bg-white">
					<image :src="goods.img" class="basis-xs radius" mode="widthFix" />
					<view class="basis-xl padding-left">
						<view>{{goods.name}}</view>
						<view class="text-red padding-top-sm padding-bottom-sm">¥{{(goods.price/100).toFixed(2)}}</view>
						<view class="text-grey">{{item.status===0?'未支付':'已支付'}}</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	//import Order from '@/components/order.vue';
	export default {
		components:{
			//Order
		},
		data() {
			return {
				filter:'',
				page:1,
				rowsPerPage:5,
				rowsNumber:0,
				list:[]
			};
		},
		onLoad(){
			this._getList();
		},
		methods:{
			_getList(){
				this.$u.api.customer_orderList({
					machineId:this.$store.state.machine._id,
					filter:this.filter,
					page:this.page,
					rowsPerPage:this.rowsPerPage,
				}).then(data => {
					this.rowsNumber=data.rowsNumber;
					//this.list=this.list.concat(data.list);
					data.list.forEach(item=>{
						this.list.push(item)
					});
				});
			},
			search(){
				this.page=1;
				this.list=[];
				this._getList();
			},
			scrolltolower(){
				if(this.rowsNumber>this.list.length){
					this.page++;
					this._getList();
				}
			},
			clickOrderId(orderId){
				uni.setClipboardData({
				    data: orderId,
				    success: function () {
				        uni.showToast({
				        	title: '已经复制订单编号信息到剪切板',  
				        	mask: false,  
				        	duration: 1500,  
				        	icon:"none"  
				        });
				    }
				});
			},
		}
	}
</script>

<style lang="scss">
</style>
